import random

setGlobalDuration(10)

patChoice = [[1,1,1,1], [1,1,2], [2,2], [4]]
def printTime():
    if ti1.getBeat() == 1 and (ti1.getBar() % 4) == 0:
        ti1.changePattern(random.choice(patChoice))
    print ti1.getBeat()

ti1 = pattern(0.125, printTime, [1,1,1,1])
ti1.start()
ti1.play()

startCsound()

